"""
Simulated upgrade firmware module with progress tracking
"""
import time

# 全局进度状态
_upgrade_progress = 0

def upgrade_firmware(device_id, firmware_version, progress_callback=None):
    """Simulate upgrading firmware for a device with progress tracking."""
    global _upgrade_progress
    
    print(f"Start upgrading firmware - Device ID: {device_id}, Version: {firmware_version}")
    
    # 重置进度状态
    _upgrade_progress = 0
    
    return {
        "status": "started",
        "message": f"Upgrade started for firmware {firmware_version}",
        "device_id": device_id,
        "firmware_version": firmware_version
    }

def get_upgrade_log():
    """Return a simulated upgrade log."""
    return [
        {"timestamp": "2024-06-01 10:00:00", "result": "success"},
        {"timestamp": "2024-05-20 09:30:00", "result": "success"}
    ]

def check_upgrade_progress():
    """Return current upgrade progress and auto-increment."""
    global _upgrade_progress
    
    # 如果进度小于100，自动增加进度
    if _upgrade_progress < 100:
        # 每次增加3.33%，模拟4.5秒完成
        _upgrade_progress = min(_upgrade_progress + 3.33, 100)
    
    return int(_upgrade_progress)
